package com.example.multithread;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.LockSupport;

public class LockSupportTest {
    public static String msg = null;
    public static void main(String[] args) {
        Thread mainThread = Thread.currentThread();
        new Thread(() -> {
            try {
                System.out.printf("【%s】准备通行数据的处理操作%n", Thread.currentThread().getName());
                TimeUnit.SECONDS.sleep(2);
                msg = "杨德军";
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            } finally {
                LockSupport.unpark(mainThread);
            }
        }, "子线程").start();
        LockSupport.park(mainThread);
        System.out.printf("【主线程】得到最终处理结果: " + msg);
    }
}
